package com.koron.css2.common.utils;

import com.aspose.words.License;
import lombok.extern.slf4j.Slf4j;

import java.io.InputStream;

@Slf4j
public class AsposeLicenseUtil {
    private static License aposeLic = new License();

    /**
     * 获取License的输入流
     *
     * @return
     */
    private static InputStream getLicenseInput() {

        InputStream inputStream = null;
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            //获取项目resource下的文件流
            inputStream = contextClassLoader.getResourceAsStream("License.xml");
        } catch (Exception e) {
            log.error("license not found!"+ e);
        }
        return inputStream;
    }

    /**
     * 设置License
     *
     * @return true表示已成功设置License, false表示失败
     */
    public static boolean setWordsLicense() {
        if (!aposeLic.getIsLicensed()) {
            try {
                aposeLic.setLicense(getLicenseInput());
                return aposeLic.getIsLicensed();
            } catch (Exception e) {
                log.error("set words license error!", e);
            }
        }
        return aposeLic.getIsLicensed();
    }



}
